home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-27 | 4.6 KB | 132 lines | [TEXT/PJMM] |
- unit PurgeFiles;
-
- interface
-
-
- uses
- Globals, NewFileUtils, HelloTabby;
-
- procedure PurgeFiles (GenericPath: str255);
-
- var
- DeleteForwards: boolean;
-
- implementation
-
- { ------------------------------------------------------ }
-
- procedure PurgeFiles;
-
- { Sets up a FwdHandleArray of up to 500 records with four fields: }
- { }
- { FileName, SendFilesName : str64 }
- { Valid, IgnoreMe : boolean }
- { }
- { The ':Tabby:AreaTrix WorkFile' is read line by line, filling }
- { in the FwdHandleArray. }
- { }
- { Then the array is analyzed. Initially both boolean fields are set }
- { to false. If the SendFilesxxx/yyy.bbs file can be opened and if }
- { it contains the FileName, then Valid is set to true. }
- { }
- { The array is stepped through with two counters. The first goes }
- { from 1 to the last array element. The second goes from the }
- { Counter1+1 to the last array element. Each time through the }
- { Counter1 loop, PendingFwd is set to false. If the IgnoreMe field }
- { of FwdHandleArray[Counter1] is false, it is set to true; if the }
- { Valid field of FwdHandleArray[Counter1] is true, PendingFwd is }
- { set to true; Counter2 is used to scan the remaining elements, }
- { looking for matches in the FileName field; if IgnoreMe is false }
- { and FileName matches FwdHandleArray[Counter1].FileName then }
- { IgnoreMe is set to true; if FwdHandleArray[Counter2].Valid is }
- { true then PendingFwd is set to true. At the end of each Counter1 }
- { loop if PendingFwd is false, FwdHandleArray[Counter1].FileName }
- { is deleted. }
-
- const
- MAXARRAY = 500;
-
- type
- FwdRecord = record
- FileName, SendFilesName: string[64];
- Valid, IgnoreMe: boolean
- end;
- FwdPtr = ^FwdRecord;
- FwdHdl = ^FwdPtr;
-
- var
- Index1, Index2, FwdLimit, WorkRef, SendRef, vRefNum: integer;
- FwdHdlArray: array[1..MAXARRAY] of FwdHdl;
- PendingFwd: boolean;
- OneLine, VolName: str255;
- Err: OSErr;
-
- begin
- Err := GetVol(@VolName, vRefNum); { Get volume ref # for default volume }
- MakeTextFile(':Tabby:AreaTrix Workfile');
- Err := FSOpen(':Tabby:AreaTrix WorkFile', vRefNum, WorkRef);
- Index1 := 0;
- while not AtEOF(WorkRef) & (Index1 < MAXARRAY) do
- begin
- Err := ReadALine(WorkRef, OneLine);
- if Err = NoErr then
- begin
- Index1 := succ(Index1);
- FwdHdlArray[Index1] := FwdHdl(NewHandle(sizeOf(FwdRecord)));
- HLock(Handle(FwdHdlArray[Index1]));
- FwdHdlArray[Index1]^^.FileName := copy(OneLine, 1, pos(TAB, OneLine) - 1);
- FwdHdlArray[Index1]^^.SendFilesName := copy(OneLine, pos(TAB, OneLine) + 1, 255);
- FwdHdlArray[Index1]^^.Valid := false;
- FwdHdlArray[Index1]^^.IgnoreMe := false;
- Err := FSOpen(concat(GenericPath, FwdHdlArray[Index1]^^.SendFilesName), vRefNum, SendRef);
- while not AtEOF(SendRef) & (Err = NoErr) do
- begin
- Err := ReadALine(SendRef, OneLine);
- if Err = NoErr then
- if pos(FwdHdlArray[Index1]^^.FileName, OneLine) > 0 then
- FwdHdlArray[Index1]^^.Valid := true;
- end; { while not AtEOF(SendRef) & (Err = NoErr) }
- Err := FSClose(SendRef);
- end; { if read WorkRef line OK }
- end; { while not AtEOF(WorkRef) }
- FwdLimit := Index1;
-
- for Index1 := 1 to FwdLimit do
- begin
- PendingFwd := false;
- if (FwdHdlArray[Index1]^^.IgnoreMe = false) then
- begin
- FwdHdlArray[Index1]^^.IgnoreMe := true;
- if FwdHdlArray[Index1]^^.Valid = true then
- PendingFwd := true;
- for Index2 := Index1 + 1 to FwdLimit do
- if (FwdHdlArray[Index2]^^.IgnoreMe = false) & (FwdHdlArray[Index1]^^.FileName = FwdHdlArray[Index2]^^.FileName) then
- begin
- FwdHdlArray[Index2]^^.IgnoreMe := true;
- if FwdHdlArray[Index2]^^.Valid = true then
- PendingFwd := true
- end;{ long if (FwdHdlArray[Index2]^^.IgnoreMe = false) etc. construction }
- if (not PendingFwd) & DeleteForwards then
- Err := FSDelete(concat(GenericPath, FwdHdlArray[Index1]^^.FileName), vRefNum);
- end; { if (FwdHdlArray[Index1]^^.IgnoreMe = false) }
- end; { for Index1 := 1 to FwdLimit }
-
- Err := FSClose(WorkRef);
-
- Err := FSDelete(':Tabby:AreaTrix WorkFile', vRefNum);
- MakeTextFile(':Tabby:AreaTrix Workfile');
- Err := FSOpen(':Tabby:AreaTrix WorkFile', vRefNum, WorkRef);
- for Index1 := 1 to FwdLimit do
- begin
- if (FwdHdlArray[Index1]^^.Valid) then
- begin
- OneLine := concat(FwdHdlArray[Index1]^^.FileName, TAB, FwdHdlArray[Index1]^^.SendFilesName);
- Err := MyWriteLine(WorkRef, OneLine);
- end;
- HUnlock(Handle(FwdHdlArray[Index1]));
- DisposHandle(Handle(FwdHdlArray[Index1]));
- end;
-
- Err := FSClose(WorkRef);
- end;
- end.